package com.bvbot.core.order;

import com.bvbot.core.BvBotException;

public class Sale {

	public int getGramsToSell() {
		return gramsToSell;
	}

	public void setGramsToSell(int gramsToSell) {
		this.gramsToSell = gramsToSell;
	}

	public int getGramsSold() {
		return gramsSold;
	}

	public void setGramsSold(int gramsSold) {
		this.gramsSold = gramsSold;
	}

	public Sale(int gramsToSell, int gramsSold) {
		super();
		this.gramsToSell = gramsToSell;
		this.gramsSold = gramsSold;
	}

	private int gramsToSell = -1;
	private int gramsSold = -1;

	public boolean allIsSold() {
		boolean result = false;
		if ((gramsToSell != -1) && (gramsSold != -1)) {
			result = (gramsToSell <= gramsSold);
		}
		return result;
	}

	public int getNextOfferGramNumber() {
		if (gramsToSell < 0) {
			BvBotException
					.exit("Impossible to compute getNextOfferGramNumber : gramsToSell is incorrect : "
							+ gramsToSell);
		}
		int gs = 0;
		if (gramsSold >= 0) {
			gs = gramsSold;
		}
		return gramsToSell - gs;
	}

	public void declareSoldGrams(int value) {
		if (gramsSold == -1) {
			gramsSold = 0;
		}
		gramsSold = gramsSold + value;
	}
}
